package org.yzh.scheduler.model.vo;

import java.io.*;

public class LogKey {

    private String jobGroup;
    private String jobName;
    private int logId;
    private long time;

    public LogKey() {
    }

    public LogKey(String jobGroup, String jobName, int logId, long time) {
        this.jobGroup = jobGroup;
        this.jobName = jobName;
        this.logId = logId;
        this.time = time;
    }

    public String getJobGroup() {
        return jobGroup;
    }

    public void setJobGroup(String jobGroup) {
        this.jobGroup = jobGroup;
    }

    public String getJobName() {
        return jobName;
    }

    public void setJobName(String jobName) {
        this.jobName = jobName;
    }

    public int getLogId() {
        return logId;
    }

    public void setLogId(int logId) {
        this.logId = logId;
    }

    public long getTime() {
        return time;
    }

    public void setTime(long time) {
        this.time = time;
    }

    public static byte[] toBytes(LogKey taskKey) {
        try (ByteArrayOutputStream bos = new ByteArrayOutputStream(64);
             DataOutputStream dos = new DataOutputStream(bos)) {

            dos.writeUTF(taskKey.jobGroup);
            dos.writeUTF(taskKey.jobName);
            dos.writeInt(taskKey.logId);
            dos.writeLong(taskKey.time);

            return bos.toByteArray();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static LogKey parse(byte[] bytes) {
        try (ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
             DataInputStream dis = new DataInputStream(bis)) {

            LogKey taskKey = new LogKey();
            taskKey.setJobGroup(dis.readUTF());
            taskKey.setJobName(dis.readUTF());
            taskKey.setLogId(dis.readInt());
            taskKey.setTime(dis.readLong());

            return taskKey;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}